package com.fzh.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fzh.mapper.OrderInfoMapper;
import com.fzh.pojo.dto.OrderInfoLinkOrderDetailsDTO;
import com.fzh.pojo.dto.OrderInfoLinkProductAndUserDTO;
import com.fzh.pojo.entity.OrderInfo;
import com.fzh.pojo.utils.ResponeMessageUtil;
import com.fzh.service.OrderInfoService;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {
	
	@Autowired
	private OrderInfoMapper orderInfoMapper;

	@Override
	public List<OrderInfo> queryAllOrderInfo(Integer page,Integer limit,String f_uid,String f_pid,String status) {
		return orderInfoMapper.selectAllOrderInfo(page,limit,f_uid,f_pid,status);
	}

	@Override
	public Integer queryOrderInfoCounts(String f_uid,String f_pid,String status) {
		return orderInfoMapper.selectOrderInfoCounts(f_uid,f_pid,status);
	}

	@Override
	public Boolean addOrderInfo(OrderInfo orderInfo) {
		
		return ResponeMessageUtil.getResMsg(orderInfoMapper.insertOrderInfo(orderInfo));
	}

	@Override
	public Boolean editOrderInfoById(OrderInfo orderInfo) {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.updateOrderInfoById(orderInfo));
	}

	@Override
	public Boolean delAllOrderInfoByIds(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		return ResponeMessageUtil.getResMsg(orderInfoMapper.deleteAllOrderInfoByIds(ids));
	}

	@Override
	public Boolean delOrderInfoById(Integer id) {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.deleteOrderInfoById(id));
	}

	@Override
	public Boolean editOrderInfoStatusById(Integer id, Integer status) {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.updateOrderInfoStatusById(id,status));
	}

	@Override
	public OrderInfo queryOrderInfoByIdWitchCartInput(Integer id) {
		return orderInfoMapper.queryOrderInfoByIdWitchCartInput(id);
	}

	@Override
	public Boolean queryAllOrderInfoByIds(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		List<OrderInfo> orderInfos = orderInfoMapper.selectAllOrderInfoByIds(ids);
		System.out.println(orderInfos.toString());
		if(orderInfos.size() > 0) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public OrderInfo queryOrderInfoById(Integer id) {
		return orderInfoMapper.selectOrderInfoById(id);
	}

	@Override
	public Boolean queryAllOrderInfoStatusByIds(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		
		List<OrderInfo> orderInfos = orderInfoMapper.selectAllOrderInfoStatusByIds(ids);
		if(orderInfos.size() > 0) {
			return true;
		}else {
			return false;
		}
		
		
	}

	@Override
	public Boolean queryAllOrderInfoByF_uids(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		List<OrderInfo> orderInfos = orderInfoMapper.selectAllOrderInfoByF_uids(ids);
		if(orderInfos.size() > 0) {
			return true;
		}else {
			return false;
		}
	}

	@Override
	public Boolean editOrderInfoStatusAllIsOne() {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.updateOrderInfoStatusAllIsOne());
	}

	@Override
	public Boolean addOrderInfoByOrderInfos(List<OrderInfo> orderInfo) {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.insertOrderInfoByOrderInfos(orderInfo));
	}

	@Override
	public List<OrderInfo> queryOrderInfoByOrderId(String out_trade_no) {
		return orderInfoMapper.selectOrderInfoByOrderId(out_trade_no);
	}

	@Override
	public void editOrderInfoByOrderId(String out_trade_no) {
		orderInfoMapper.updateOrderInfoByOrderIdF(out_trade_no);
	}

	@Override
	public Boolean addOrderInfoByOrderInfoDTOF(OrderInfoLinkProductAndUserDTO orderInfo) {
		return ResponeMessageUtil.getResMsg(orderInfoMapper.insertOrderInfoByOrderInfoDTOF(orderInfo));
	}

	@Override
	public OrderInfo findOrderInfoDetails(Integer id) {
		return orderInfoMapper.selectOrderInfoById(id);
	}

	@Override
	public int editOrderInfoByOrderStatus(String orderId) {
		return orderInfoMapper.updateOrderInfoByOrderStatus(orderId);
	}
	
	@Override
	public int editOrderInfoByOrderStatus1(String orderId) {
		return orderInfoMapper.updateOrderInfoByOrderStatus1(orderId);
	}

	@Override
	public OrderInfoLinkOrderDetailsDTO selectOrderDetailsAll(String orderId) {
		return orderInfoMapper.selectOrderDetailsAll(orderId);
	}

}
